//
//  SeckillGoodsModel.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/9.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "SeckillGoodsModel.h"

@interface SeckillGoodsModel()
{
    NSInteger _cntNum;
}
@end

@implementation SeckillGoodsModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"secKillGoodsId":@"id"};
}

- (NSString *)description {
    NSArray *ptyArr = @[@"price",@"market_price",@"goods_type",@"name",@"end_time"];
    
    return [[self dictionaryWithValuesForKeys:ptyArr] description];
}
#pragma mark - 一 接口

- (void)countDown {
    
    _cntNum = [self theInteverBetweenCurrentTimeAndEndTime];
    _cntNum --;
}

- (NSString *)currentTimeString {
    if (_cntNum <= 0) {
        return @"00:00:00";
    }else {
        NSString *ctStr = [NSString stringWithFormat:@"  %02ld:%02ld:%02ld后结束" ,_cntNum/3600 ,_cntNum%3600/60 ,_cntNum%60];
        return ctStr;
    }
}

#pragma mark - 二 Private mehtod

/**结束时间 - 系统时间的时间差*/
- (NSInteger)theInteverBetweenCurrentTimeAndEndTime {
    
    NSInteger c = [self currentTimeStamp];
    
    NSInteger e = [self.end_time integerValue];
    
    //再将时间转换为秒
    return (e-c) / 1000;
}

/**系统当前时间的时间戳*/
- (NSInteger)currentTimeStamp {
    
    NSInteger timeStamp = [[NSDate date] timeIntervalSince1970];
    
    //Java 的 时间戳单位好像是毫秒。这里保持单位一致
    return timeStamp *1000;
}


@end
